// Problem 039: Integer right triangles
// If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.
// {20,48,52}, {24,45,51}, {30,40,50}
// For which value of p ≤ 1000, is the number of solutions maximised?

package main

import (
	"fmt"
)

func p039() {
	max, val, cur := 0, 0, 0
	for p := 121; p <= 1000; p++ {
		cur = 0
		for c := p / 3; c < p/2; c++ {
			for a := 1; a <= (p-c)/2; a++ {
				if b := p - c - a; b*b+a*a == c*c {
					cur++
				}
			}
		}
		if max < cur {
			max, val = cur, p
		}
	}
	fmt.Println("Problem 039:", val)
}
